package com.lagou.homework.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

// 输入：k: 偏移量    v: 每一行的数据
// 输出：k: 原始数据转为LongWritable  v:Null
public class SortFileNumMapper extends Mapper<LongWritable, Text, LongWritable,NullWritable> {

    final LongWritable out = new LongWritable();

    // MapTask 和 ReduceTask 都会根据key对数据进行排序。属于hadoop默认行为
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        long num = Long.parseLong(value.toString());
        out.set(num);
        context.write(out,NullWritable.get());
    }
}
